﻿using DataService.Common;
using DataService.Core.ServiceDTO;
using DataService.DataAccessLayer;
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Text;

namespace DataService.Remote.DataAccessLayer.Provider
{
    public class DMProvider : DatabaseProvider
    {
        //DM 数据库支持三种事务隔离级别：读未提交、读提交和串行化，不支持可重复读。
        public override DatabaseType DBType => DatabaseType.DaMeng;
        public override Type DatabaseProviderType => typeof(DMProvider);
        private static DbProviderFactory _DMFactory;
        public override DbProviderFactory ProviderFactory
        {
            get
            {
                if (_DMFactory == null)
                {
                    lock (typeof(DMProvider))
                    {
                        string dir = Core.Common.FilePathHelper.BasePath + "DmProvider.dll";
                        _DMFactory = GetProviderFactory(dir, "Dm.DmClientFactory");
                       // System.Console.WriteLine("实例化 达梦 驱动工厂");
                    }
                }

                return _DMFactory;
            }
        }
      


        //public static void GetDMDbProviderFactory()
        //{
        //    DbProviderFactory factory = DbProviderFactories.GetFactory("Dm");
        //    DbConnection sconn = factory.CreateConnection();
        //    sconn.ConnectionString = "Server=localhost; UserId=SYSDBA; PWD=SYSDBA";
        //    sconn.Open();
        //    DbCommand scmd = factory.CreateCommand();
        //    scmd.Connection = sconn;
        //    try
        //    {
        //        scmd.CommandText = "drop table t1 cascade;";
        //        scmd.ExecuteNonQuery();
        //    }
        //    catch (Exception)
        //    { }
        //}
    }
}
